<template>
  <div class="tenantMenu_main main_container">
    <div>
      <el-tabs v-model="activeName" @tab-click="tabClick">
        <el-tab-pane label="销售订单" name="1" />
        <el-tab-pane label="采购订单" name="2" />
        <el-tab-pane label="外协订单" name="3" />
      </el-tabs>
    </div>
    <div v-loading="loading" class="main_main">
      <div class="SearchBar_main main_main_search">
        <div class="main_main_search_item">
          <el-input v-model="pageData.searchValue" class="search_input" placeholder="请输入订单号" clearable @keyup.enter.native="()=>{pageData.pageNum=1; getList()}" @clear="getList" />
          <el-button class="button_icon" icon="el-icon-search" @click.stop="()=>{pageData.pageNum=1; getList()}" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :row-class-name="tableRowClass"
          :height="tableHeight"
          stripe
          border
          @row-click="chooseOrder"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" :min-width="column.minWidth" />
          <el-table-column
            label="附件"
            min-width="80"
          >
            <template slot-scope="scope">
              <FileManage
                :file-names="scope.row.fileName"
                :file-real-names="scope.row.fileRealName"
                :file-urls="scope.row.url"
                :readonly="true"
                class="accessory"
                @fileName="setFileName"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import {
  listForReturn,
  listOutsource,
  listPurchase
} from '@/api/receivableAndPayable/receivableAndPayableManage/additionalReceipt'
// import { purchaseOrderList } from '@/api/purchaseManage/purchaseOrder'
// import { list as outsourceOrderList } from '@/api/outsourceManage/outsourceOrder'
export default {
  props: {
    layerid: {},
    id: {},
    selectionId: {},
    formId: {}
  },
  data() {
    return {
      templateSelection: '',
      loading: false,
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        searchValue: ''
      },
      // tableKey: 1,
      activeName: '1',
      total: '', // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '采购订单号', minWidth: '120' },
        { prop: 'orderName', label: '采购人员', minWidth: '100' },
        { prop: 'supplierName', label: '供应商', minWidth: '100' },
        { prop: 'orderTime', label: '采购日期', minWidth: '140' },
        { prop: 'hasPrice', label: '已付款金额', minWidth: '140' },
        { prop: 'unPrice', label: '未付款金额', minWidth: '140' },
        { prop: 'allPurchaseNumber', label: '采购数量', minWidth: '140' },
        { prop: 'taxTotalMoney', label: '含税总金额', minWidth: this.SETTINGS.settings_decimalDigits_length },
        { prop: 'remark', label: '备注', minWidth: '200' }
      ]
    }
  },
  watch: {
    activeName: {
      handler() {
        this.pageData = {
          pageNum: 1,
          pageSize: 20,
          orderByColumn: 'updateTime',
          isAsc: 'desc',
          searchValue: ''
        }
        this.loading = true
        this.getList()
      },
      deep: true,
      immediate: true
    }
  },
  created() {
  },
  mounted() {
    if (this.selectionId) {
      this.templateSelection = this.selectionId
    }
  },
  methods: {
    tabClick(e, a) {
    },
    // tableRowClass({ row }) {
    //   if (row.id == this.formId) {
    //     return 'rowSelected'
    //   } else {
    //     return ''
    //   }
    // },
    getList() {
      if (this.activeName == '1') {
        this.defaultTableColumns = [// 表格常规字段（初始值）
          { prop: 'code', label: '销售订单号', minWidth: '120' },
          { prop: 'orderName', label: '销售人员', minWidth: '100' },
          { prop: 'customerName', label: '客户名称', minWidth: '100' },
          { prop: 'orderGoodsTime', label: '订货日期', minWidth: '140' },
          { prop: 'contractCode', label: '合同号', minWidth: '100' },
          { prop: 'hasPrice', label: '已收款金额', minWidth: '100' },
          { prop: 'unPrice', label: '未收款金额', minWidth: '100' },
          { prop: 'orderNumber', label: '订单数量', minWidth: '100' },
          { prop: 'taxAllPrice', label: '含税总金额', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right' },
          { prop: 'tax', label: '税额', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right' },
          { prop: 'remark', label: '备注', minWidth: '200' }
        ]
        listForReturn({ ...this.pageData, statusList: ['4', '5', '6', '7'] }).then(res => {
          this.tableData = res.data
          this.total = res.total
          this.loading = false
          this.$nextTick(() => {
            this.setSelectRow(this)// 设置行选中
            this.tableHeight = this.$refs.table_container.offsetHeight
          })
        })
      } else if (this.activeName == '2') {
        this.defaultTableColumns = [// 表格常规字段（初始值）
          { prop: 'code', label: '采购订单号' },
          { prop: 'orderName', label: '采购人员', canOrder: false },
          { prop: 'supplierName', label: '供应商', canOrder: false },
          { prop: 'orderTime', label: '采购日期' },
          { prop: 'hasPrice', label: '已付款金额', minWidth: '100' },
          { prop: 'unPrice', label: '未付款金额', minWidth: '100' },
          { prop: 'allPurchaseNumber', label: '采购数量', minWidth: '100' },
          { prop: 'taxTotalMoney', label: '含税总金额', canOrder: false, minWidth: '120' },
          { prop: 'remark', label: '备注', canOrder: false }
        ]
        listPurchase({ ...this.pageData }).then(res => {
          this.tableData = res.data
          this.total = res.total
          this.loading = false
          this.$nextTick(() => {
            this.setSelectRow(this)// 设置行选中
            this.tableHeight = this.$refs.table_container.offsetHeight
          })
        })
      } else {
        this.defaultTableColumns = [
        // 表格常规字段（初始值）
          { prop: 'code', label: '外协订单号' },
          { prop: 'orderName', label: '制单人员', canOrder: false },
          { prop: 'supplierName', label: '外协供应商', canOrder: false },
          { prop: 'orderTime', label: '制单日期' },
          { prop: 'hasPrice', label: '已付款金额', minWidth: '100' },
          { prop: 'unPrice', label: '未付款金额', minWidth: '100' },
          { prop: 'allOutsourceNumber', label: '外协总数量', minWidth: this.SETTINGS.settings_decimalDigits_length, canOrder: false },
          { prop: 'taxTotalMoney', label: '含税总金额', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right', canOrder: false },
          { prop: 'remark', label: '备注', canOrder: false }
        ]
        listOutsource({ ...this.pageData, statusList: ['4', '3', '2', '1'] }).then(res => {
          this.tableData = res.data
          this.total = res.total
          this.loading = false
          this.$nextTick(() => {
            this.setSelectRow(this)// 设置行选中
            this.tableHeight = this.$refs.table_container.offsetHeight
          })
        })
      }
    },
    setFileName(...data) {
      this.tableData[data[3]].fileName = data[0]
      this.tableData[data[3]].fileRealName = data[1]
      this.tableData[data[3]].url = data[2]
    },
    chooseOrder(row) {
      if (row.taxTotalMoneyThousandths) {
        row.taxAllPrice = row.taxTotalMoneyThousandths
      } else if (row.totalTaxPrice) {
        row.taxAllPrice = row.totalTaxPrice
      } else if (row.taxTotalMoneyThousandths) {
        row.taxAllPrice = row.taxTotalMoneyThousandths
      }
      this.$parent.chooseOrderBack(row, this.activeName)
      this.$layer.close(this.layerid)
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.el-tabs__header{
  margin: 1px !important;
}
.button{
  width: 100px;
  height: 30px;
  color: #fff;
  background-color: #387bfc;
  border-radius: 4px;
  text-align: center;
  line-height: 30px;
}
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}

.table_container{
  margin-top: 20px !important;
}
.addtype-main_bottoms{
  padding-right: 20px !important;
  margin: 10px 0;
}
.main_search_item{
  padding-right: 20px !important;
}
.main_main_search{
  padding-right: 20px !important;
}
.main_main_search_item{
  padding-left: 20px !important;
}
.main_main{
  margin: 0 !important;
  padding-top:0 !important;
  height: calc(100% - 100px) !important;
}
.button_icon{
  background:#387bfc;
  width:30px;
}
.search_input{
  width:200px;
  margin-right:10px
}
/deep/ .el-input--suffix .el-input__inner {
  padding-right: 25px;
}
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
</style>
